<?php
define( 'DS' , DIRECTORY_SEPARATOR );
define( 'APP_ROOT' ,  dirname( dirname( __FILE__ )  ) . DS );

define( 'BLAB_ROOT' , dirname( __FILE__ ) . DS  );
define( 'LP3K_ROOT' , APP_ROOT.'lp3k'.DS  );



// include_once KIS_APP_ROOT.'ext_lib'. DS.'comm.function.php';
define( 'AROOT' , LP3K_ROOT.'php'.DS);
define( 'CROOT' , AROOT.'_lp'. DS.'core'. DS  );
require_once CROOT. 'lib'.DS.'core.function.php';

require_once 'config.php';
require_once 'incl/main.inc';

dbconnect(); $settings=get_settings(0); $options=get_options(); $lang=get_language(); 

$query='DELETE FROM '.$dbss['prfx']."_ban WHERE timestamp<$timestamp";
neutral_query($query);

unset($user);
if(isset($_COOKIE['blab8_xuidc'])){

$uid=explode('z',$_COOKIE['blab8_xuidc']);

if(isset($uid[1]) && hsh($uid[0].$settings['cookie_salt'])==$uid[1]){
$uid=(int)$uid[0];

$query='SELECT * FROM '.$dbss['prfx']."_users WHERE usr_id=$uid";
$result=neutral_query($query);

if(neutral_num_rows($result)>0){
	$ext_user=neutral_fetch_array($result);

	$user=array();
	$user['id']=(int)$ext_user['usr_id'];
	$user['name']=$ext_user['usr_name'];
	$user['room_id']=$ext_user['usr_room'];
}
}}

if(!isset($user['id']) || !$user['name']){redirect('login.php');die();}

$ajx_name=$user['name']; $ajx_name=trim($ajx_name);
$ajx_name=abc123($ajx_name,'*');

$lhash=hsh($user['id'].'hash_check');
$uhash=hsh($user['id'].$ajx_name.'blab'); 
$js_vars='uid='.$user['id'].';uname=\''.$ajx_name.'\';uhash=\''.$uhash.'\';';
$js_vars.='rid='.intval($user['room_id']).';';

if(isset($settings['iplog_on'])){
	$iplname=neutral_escape($user['name'],64,'str');
	$ipaddrs=$_SERVER['REMOTE_ADDR'];
	$query='SELECT * FROM '.$dbss['prfx'].'_iplog WHERE usr_id='.$user['id'].' AND ipaddr=\''.$ipaddrs.'\'';
	$result=neutral_query($query);

	if(neutral_num_rows($result)<1){
	$query='INSERT INTO '.$dbss['prfx'].'_iplog VALUES('.$user['id'].',\''.$iplname.'\',\''.$ipaddrs.'\','.$timestamp.')';
	neutral_query($query);}
	else{
	$query='UPDATE '.$dbss['prfx'].'_iplog SET timestamp='.$timestamp.' WHERE usr_id='.$user['id'].' AND ipaddr=\''.$ipaddrs.'\'';
	neutral_query($query);}
}

	require_once BLAB_ROOT.'incl/rpg_infos.inc.php';
// SELECT * FROM `chat_room` WHERE 1
	$tmpjs='';
	$tmpSql="SELECT * FROM `chat_room` WHERE `status_id`=2 ";
	$retSql = get_data($tmpSql);
	if($retSql!==false){		
		$max=count($retSql);
		if($max>24) $max=24;
		$i=0;
		$act='AddMetroSimpleBtnWithBGColor';
		foreach ($retSql as $key => $value) {
			$id=$i+1;
			if($i<24){		
				if(isset($value['title']) && isset($value['content'])){
		           	$titl=$value['title'];
		           	$titl=str_replace('(', ' ', $titl);
		           	$titl=str_replace(')', ' ', $titl);
		           	$tmpArr2=explode('-', $titl);
		           	$titl=implode(' ' , $tmpArr2);
		           	$pic=$logoArr[mt_rand(0,count($logoArr)-1)];
		           	$pic = preg_replace('/[\x00-\x1f]|\x7f/i', '', $pic);//\x00-\x1f是不可见的控制字符，\x7f是delete，也不可见，所以替换掉
		           	$tmpjs .= '$("#metrobuttons").'.$act."('mbtn".$id."', '".$colorArr[$i]."', 'static/citylogo/".$pic."', '".$titl."', '".'join_room('.$id.');'."');";
					$tmpjs .=PHP_EOL;
		        }
			}
			$i++;
	    }
	}

	// require_once BLAB_ROOT.'incl/rpg_infos.inc.php';
	// $max=count($cityArr);
	// for ($i=0; $i < $max; $i++) { 
	// 	$id=$i+1;
	// 	// $rid=mt_rand(100,999);
	// 	// $titl='Room #'.$id.' '.$rid.' '.$cityArr[$i];
	// 	$titl='#'.$id.' '.$cityArr[$i];
	// 	$act='AddMetroSimpleBtnWithBGColor';
	// 	$pic=$logoArr[mt_rand(0,count($logoArr)-1)];
	
	// 	$tmpSrc = '$("#metrobuttons").'.$act."('mbtn".$id."', '".$colorArr[$i]."', 'static/citylogo/".$pic."', '".$titl."', '".'join_room("'.$id.'");'."');";
	// 	echo $tmpSrc.PHP_EOL;
	// }

include 'ui/smilies.inc';

$title=$settings['title'];
include 'ui/templates/head.pxtm';
include 'ui/templates/join_world.inc.php';


?>